package cinema.ELTEcinema;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.enterprise.context.SessionScoped;
import javax.inject.Inject;
import javax.inject.Named;

import cinema.ELTEcinema_ejb.Dao.MovieDAO;
import cinema.ELTEcinema_ejb.Dao.RoomDAO;
import cinema.ELTEcinema_ejb.Dao.TimeTableDAO;
import cinema.ELTEcinema_ejb.Entity.Movie;
import cinema.ELTEcinema_ejb.Entity.Room;
import cinema.ELTEcinema_ejb.Entity.TimeTable;

@SuppressWarnings("serial")
@Named
@SessionScoped
public class MainController implements Serializable{

	@Inject
	private TimeTableDAO timeTableDAO;

	private Date filterDate;

	private List<TimeTable> filteredTimeTables;
	
	@PostConstruct
	public void init(){
		filterDate=new Date();
		filter();
	}

	@SuppressWarnings("deprecation")
	public void filter(){
		filteredTimeTables = new ArrayList<TimeTable>();
		List<TimeTable> fullTimeTable = timeTableDAO.findAll();
		for(TimeTable t : fullTimeTable){
			Date time = t.getStartTime();
			if(time.getDate() == filterDate.getDate() &&
			   time.getMonth() == filterDate.getMonth() &&
			   time.getYear() == filterDate.getYear())
				filteredTimeTables.add(new TimeTable(t));
		}
	}

	public Date getFilterDate() {
		return filterDate;
	}

	public void setFilterDate(Date filterDate) {
		this.filterDate = filterDate;
	}

	public List<TimeTable> getFilteredTimeTables() {
		return filteredTimeTables;
	}

	public void setFilteredTimeTables(List<TimeTable> filteredTimeTables) {
		this.filteredTimeTables = filteredTimeTables;
	}
}
